package com.canplay.screen.init

import android.app.Application
import android.content.Context
import androidx.startup.Initializer
import com.canplay.screen.BuildConfig
import com.elvishew.xlog.LogConfiguration
import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.XLog
import com.elvishew.xlog.printer.AndroidPrinter
import com.tencent.mmkv.MMKV

val appContext:Application by lazy { CoreInitializer.applicationContext }

class CoreInitializer:Initializer<Unit> {

    companion object{
        lateinit var applicationContext: Application
    }

    override fun create(context: Context) {
        applicationContext = context.applicationContext as Application
        MMKV.initialize(context)
        val logConfiguration = LogConfiguration.Builder()
            .tag("SALT_LOG")
            .logLevel(if (BuildConfig.DEBUG) LogLevel.ALL else LogLevel.NONE)
            .enableBorder()
            .enableThreadInfo()
            .build()
        XLog.init(logConfiguration,AndroidPrinter(true))
    }

    override fun dependencies(): MutableList<Class<out Initializer<*>>> {
        return mutableListOf()
    }
}